package base.day14.dao;

import base.day14.domain.Student;
import base.day14.service.StudentService;

public class  StudentDao {
    //创建学生对象数组
    static Student[] stus=new Student[5];

    public static void deldteStudentById(String deid) {
        int index=getIndex(deid);
        stus[index]=null;
    }
    public static int getIndex(String id){
        int index=-1;
        for (int i = 0; i < stus.length; i++) {
            Student stu=stus[i];
            if (stu!=null&&stu.getId().equals(id)){
                index=i;
                break;
            }
        }
        return index;
    }

    public boolean addStudent(Student stu) {
        //创建一个index变量，判断数组中是否还有位置
        int index=-1;
        for (int i = 0; i < stus.length; i++) {
            if (stus[i]==null){
                index=i;
                break;
            }
        }
        //判段数组index是否满足条件返回boolaen
        //转满了
        if (index==-1){
            return false;
        }
        //没有装满正常添加
        else{
            stus[index]=stu;
            return true;
        }
    }

    public Student[] findAllStudent() {
        return stus;
    }

    public void studentDao(String upateId, Student newstu) {
        int index = getIndex(upateId);
        stus[index]=newstu;
    }
}
